/**
 * 
 */
var Util = function() {
    return {
        assert: function(b, a) {
            if (!b) {
                alert(a)
            }
        },
        assertNotBlank: function(b, a) {
            if (b == undefined || $.trim(b) == "") {
                Util.assert(false, a);
                return
            }
        },
        hashCode: function(c) {
            var b = 0;
            if (c.length == 0) {
                return b
            }
            for (i = 0; i < c.length; i++) {
                var a = c.charCodeAt(i);
                b = ((b << 5) - b) + a;
                b = b & b
            }
            if (b < 0) {
                b = -b
            }
            return b
        },
        AddOrReplaceUrlParameter: function(f, a, e) {
            var d = f.indexOf("?");
            if (d == -1) {
                f = f + "?" + a + "=" + e
            } else {
                var g = f.split("?");
                var h = g[1].split("&");
                var c = "";
                var b = false;
                for (i = 0; i < h.length; i++) {
                    c = h[i].split("=")[0];
                    if (c == a) {
                        h[i] = a + "=" + e;
                        b = true;
                        break
                    }
                }
                if (!b) {
                    f = f + "&" + a + "=" + e
                } else {
                    f = g[0] + "?";
                    for (i = 0; i < h.length; i++) {
                        if (i > 0) {
                            f = f + "&"
                        }
                        f = f + h[i]
                    }
                }
            }
            return f
        },
        getParameterFromUrl: function(c, b) {
            var d = new RegExp("(\\?|&)" + b + "=([^&?]*)", "i");
            var a = c.match(d);
            if (a) {
                return a[2]
            }
            return null
        },
        subStringBetween: function(d, f, b) {
            var e = new RegExp(f + ".*?" + b, "img");
            var c = new RegExp(f, "g");
            var a = new RegExp(b, "g");
            return d.match(e).join("=").replace(c, "").replace(a, "").split("=")
        },
        split: function(a) {
            return a.split(",")
        },
        isArrayContainElement: function(c, b) {
            var a = c.length;
            while (a--) {
                if (c[a] == b) {
                    return true
                }
            }
            return false
        },
        getTextWithoutChildren: function(a) {
            return $(a)[0].childNodes[0].nodeValue.trim()
        },
        findClosestFormInputByName: function(b, a) {
            return $(b).closest("form").find("[name='" + a + "']")
        },
        setInputValIfBlank: function(a, b) {
            if ($.trim($(a).val()) == "") {
                $(a).val(b)
            }
        },
        unEditable: function(b) {
            var a = $(b);
            return a.attr("readonly") || a.attr("disabled")
        },
        startWith: function(b, c) {
            var a = new RegExp("^" + c);
            return a.test(b)
        },
        endWith: function(c, a) {
            var b = new RegExp(a + "$");
            return b.test(c)
        },
        objectToString: function(a) {
            if (a == undefined) {
                return "undefined"
            }
            var b = "";
            $.each(a,
            function(d, c) {
                b += (d + ":" + c + ";\n")
            });
            return b
        },
        parseFloatValDefaultZero: function(b) {
            if ($.trim($(b).val()) == "") {
                return 0
            } else {
                var a = parseFloat($.trim($(b).val()));
                if (isNaN(a)) {
                    return 0
                } else {
                    return a
                }
            }
        },
        notSmallViewport: function() {
            var a = $(window).width();
            return a >= 768
        },
        ajaxJsonUrl:function(b, d, c) {
            Util.assertNotBlank(b, "ajaxJsonUrl调用的url参数不能为空");
            var a = $(this);
            Global.blockUI();
            $.ajax({
                traditional: true,
                type: "GET",
                cache: false,
                url: b,
                dataType: "json",
                data: c,
                success: function(e) {
                    if (e.type == "error" || e.type == "warning" || e.type == "failure") {
                        Global.notify("error", e.message)
                    } else {
                        if (d) {
                            d.call(a, e)
                        }
                        json = e
                    }
                    Global.unblockUI()
                },
                error: function(g, e, f) {
                    Global.notify("error", "数据请求异常，请联系管理员", "系统错误");
                    Global.unblockUI(a)
                },
                statusCode: {
                    403 : function() {
                        Global.notify("error", "URL: " + b, "未授权访问")
                    },
                    404 : function() {
                        Global.notify("error", "请尝试刷新页面试试，如果问题依然请联系管理员", "请求资源未找到")
                    }
                }
            })
        },
        ajaxGetPage:function(b, c, d){
        	Util.assertNotBlank(b, "ajaxGetUrl调用的url参数不能为空");
            var a = $("<div class='ajax-page-inner'/>");
            Global.blockUI(a);
            $.ajax({
                type: "GET",
                cache: false,
                url: b,
                data: c,
                dataType: "html",
                headers: {
                    decorator: "body"
                },
                success: function(f) {
                    a.html(f);
                    if (d) {
                        d.call(a, f)
                    }                    
                    App.unblockUI();
                   
                },
                error: function(g, e, f) {
                    if (g.status == 400) {
                        a.html(g.responseText)
                    } else {
                        a.html("<h4>页面内容加载失败</h4>" + g.responseText)
                    }
                    App.unblockUI(a)
                },
                statusCode: {
                    403 : function() {
                        Global.notify("error", "URL: " + b, "未授权访问")
                    },
                    404 : function() {
                        Global.notify("error", "页面未找到：" + b + "，请联系管理员", "请求资源未找到")
                    }
                }
            });
            return a
        }
      }
} ();
var BooleanUtil = function() {
    return {
        toBoolean: function(b) {
            if (b) {
                var a = $.type(b);
                if (a === "string" && (b == "true" || b == "1" || b == "y" || b == "yes" || b == "readonly" || b == "checked" || b == "enabled" || b == "enable" || b == "selected")) {
                    return true
                } else {
                    if (a === "number" && (b == 1)) {
                        return true
                    }
                }
            }
            return false
        }
    }
} ();
var MathUtil = function() {
    return {
        mul: function(arg1, arg2) {
            if (arg1 == undefined) {
                arg1 = 0
            }
            var m = 0,
            s1 = arg1.toString(),
            s2 = arg2.toString();
            try {
                m += s1.split(".")[1].length
            } catch(e) {}
            try {
                m += s2.split(".")[1].length
            } catch(e) {}
            return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
        },
        div: function(arg1, arg2, fix) {
            if (fix == undefined) {
                fix = 2
            }
            var t1 = 0,
            t2 = 0,
            r1, r2;
            try {
                t1 = arg1.toString().split(".")[1].length
            } catch(e) {}
            try {
                t2 = arg2.toString().split(".")[1].length
            } catch(e) {}
            with(Math) {
                r1 = Number(arg1.toString().replace(".", ""));
                r2 = Number(arg2.toString().replace(".", ""));
                return MathUtil.mul((r1 / r2), pow(10, t2 - t1)).toFixed(fix)
            }
        },
        add: function(arg1, arg2) {
            if (arg1 == undefined) {
                arg1 = 0
            }
            if (arg2 == undefined) {
                arg2 = 0
            }
            var r1, r2, m, c;
            try {
                r1 = arg1.toString().split(".")[1].length
            } catch(e) {
                r1 = 0
            }
            try {
                r2 = arg2.toString().split(".")[1].length
            } catch(e) {
                r2 = 0
            }
            c = Math.abs(r1 - r2);
            m = Math.pow(10, Math.max(r1, r2));
            if (c > 0) {
                var cm = Math.pow(10, c);
                if (r1 > r2) {
                    arg1 = Number(arg1.toString().replace(".", ""));
                    arg2 = Number(arg2.toString().replace(".", "")) * cm
                } else {
                    arg1 = Number(arg1.toString().replace(".", "")) * cm;
                    arg2 = Number(arg2.toString().replace(".", ""))
                }
            } else {
                arg1 = Number(arg1.toString().replace(".", ""));
                arg2 = Number(arg2.toString().replace(".", ""))
            }
            return MathUtil.div((arg1 + arg2), m)
        },
        sub: function(arg1, arg2) {
            return MathUtil.add(arg1, -Number(arg2))
        }
    }
} ();
function scanBarcodeCallback(b, a) {
    $("#" + b).trigger("barcode", [a])
};